# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

cc_library(
    name = "hbase",
    hdrs = [
        "hbase_channel.h",
        "hbase_client_controller.h",
        "hbase_server_controller.h",
        "hbase_service.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":hbase_client",
        ":hbase_server",
    ],
)

cc_library(
    name = "hbase_client",
    hdrs = [
        "hbase_channel.h",
        "hbase_client_controller.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":hbase_channel",
        ":hbase_client_controller",
        ":hbase_client_protocol",
    ],
)

cc_library(
    name = "hbase_server",
    hdrs = [
        "hbase_server_controller.h",
        "hbase_service.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":hbase_server_controller",
        ":hbase_server_protocol",
        ":hbase_service",
    ],
)

cc_library(
    name = "call_context",
    srcs = ["call_context.cc"],
    hdrs = ["call_context.h"],
    deps = [
        "//flare/net/hbase/proto:rpc_cc_proto",
        "//flare/rpc/protocol:controller",
    ],
)

cc_library(
    name = "call_context_factory",
    srcs = ["call_context_factory.cc"],
    hdrs = ["call_context_factory.h"],
    deps = [
        ":call_context",
        ":hbase_server_controller",
        "//flare/base:chrono",
        "//flare/rpc/protocol:controller",
    ],
)

cc_library(
    name = "message",
    srcs = ["message.cc"],
    hdrs = ["message.h"],
    deps = [
        "//flare/base:buffer",
        "//flare/base:endian",
        "//flare/base:maybe_owning",
        "//flare/base/buffer:zero_copy_stream",
        "//flare/net/hbase/proto:constants",
        "//flare/net/hbase/proto:rpc_cc_proto",
        "//flare/rpc/protocol:message",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "hbase_channel",
    srcs = ["hbase_channel.cc"],
    hdrs = ["hbase_channel.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":hbase_client_controller",
        ":hbase_client_protocol",
        ":message",
        "//flare/base:callback",
        "//flare/base:down_cast",
        "//flare/base:random",
        "//flare/base:string",
        "//flare/base/net:endpoint",
        "//flare/fiber",
        "//flare/rpc/internal:correlation_id",
        "//flare/rpc/internal:stream_call_gate",
        "//flare/rpc/internal:stream_call_gate_pool",
        "//flare/rpc/name_resolver",
        "//flare/rpc/name_resolver:list",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "hbase_channel_test",
    srcs = ["hbase_channel_test.cc"],
    deps = [
        ":hbase_channel",
        ":hbase_client_controller",
        ":hbase_server_controller",
        ":hbase_service",
        "//flare/rpc",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:endpoint",
        "//flare/testing:main",
        "//flare/testing:rpc_mock",
    ],
)

cc_library(
    name = "hbase_controller_common",
    srcs = ["hbase_controller_common.cc"],
    hdrs = ["hbase_controller_common.h"],
    deps = [
        "//flare/base:buffer",
        "//flare/base:logging",
        "//flare/base/internal:time_view",
        "//flare/base/internal:test_prod",
        "//flare/base/net:endpoint",
        "//flare/net/hbase/proto:constants",
        "//flare/net/hbase/proto:rpc_cc_proto",
    ],
)

cc_test(
    name = "hbase_controller_common_test",
    srcs = ["hbase_controller_common_test.cc"],
    deps = [
        ":hbase_controller_common",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "hbase_client_controller",
    srcs = ["hbase_client_controller.cc"],
    hdrs = ["hbase_client_controller.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":call_context",
        ":hbase_controller_common",
    ],
)

cc_test(
    name = "hbase_client_controller_test",
    srcs = ["hbase_client_controller_test.cc"],
    deps = [
        ":hbase_client_controller",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "hbase_server_controller",
    srcs = ["hbase_server_controller.cc"],
    hdrs = ["hbase_server_controller.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":hbase_controller_common",
        "//flare/base/internal:early_init",
        "//flare/base/internal:test_prod",
    ],
)

cc_test(
    name = "hbase_server_controller_test",
    srcs = ["hbase_server_controller_test.cc"],
    deps = [
        ":hbase_server_controller",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "hbase_client_protocol",
    srcs = ["hbase_client_protocol.cc"],
    hdrs = ["hbase_client_protocol.h"],
    deps = [
        ":call_context",
        ":call_context_factory",
        ":hbase_client_controller",
        ":message",
        "//flare/base:down_cast",
        "//flare/base:endian",
        "//flare/base:logging",
        "//flare/base/buffer:zero_copy_stream",
        "//flare/base/internal:test_prod",
        "//flare/net/hbase/proto:rpc_cc_proto",
        "//flare/rpc/protocol:controller",
        "//flare/rpc/protocol:message",
        "//flare/rpc/protocol:stream_protocol",
    ],
)

cc_library(
    name = "hbase_server_protocol",
    srcs = ["hbase_server_protocol.cc"],
    hdrs = ["hbase_server_protocol.h"],
    deps = [
        ":call_context",
        ":call_context_factory",
        ":hbase_server_controller",
        ":message",
        "//flare/base:down_cast",
        "//flare/base:endian",
        "//flare/base:logging",
        "//flare/base/buffer:zero_copy_stream",
        "//flare/base/internal:test_prod",
        "//flare/net/hbase/proto:rpc_cc_proto",
        "//flare/rpc/protocol:message",
        "//flare/rpc/protocol:stream_protocol",
    ],
)

cc_test(
    name = "hbase_protocol_test",
    srcs = ["hbase_protocol_test.cc"],
    deps = [
        ":call_context",
        ":hbase_client_controller",
        ":hbase_client_protocol",
        ":hbase_server_controller",
        ":hbase_server_protocol",
        ":message",
        "//flare/base:down_cast",
        "//flare/init:on_init",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "hbase_service",
    srcs = ["hbase_service.cc"],
    hdrs = ["hbase_service.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":call_context",
        ":hbase_server_controller",
        ":hbase_server_protocol",
        ":message",
        "//flare/base:callback",
        "//flare/base:down_cast",
        "//flare/base/internal:lazy_init",
        "//flare/fiber",
        "//flare/net/hbase/proto:rpc_cc_proto",
        "//flare/rpc/internal:fast_latch",
        "//flare/rpc/internal:rpc_metrics",
        "//flare/rpc/protocol:stream_service",
    ],
)

cc_test(
    name = "hbase_service_test",
    srcs = ["hbase_service_test.cc"],
    deps = [
        ":call_context",
        ":hbase_server_controller",
        ":hbase_service",
        ":message",
        "//flare/base:down_cast",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:main",
    ],
)
